<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <link href="jquery/bootstrap_3.3.0/css/bootstrap.min.css" type="text/css" rel="stylesheet"/>
    <script type="text/javascript" src="jquery/jquery-1.11.1-min.js"></script>
    <script type="text/javascript" src="jquery/bootstrap_3.3.0/js/bootstrap.min.js"></script>
</head>
<body>
<div style="position: absolute; top: 0px; left: 0px; width: 60%;">
    <img src="image/IMG_7114.JPG" style="width: 100%; height: 90%; position: relative; top: 50px;">
</div>
<div id="top" style="height: 50px; background-color: #3C3C3C; width: 100%;">
    <div style="position: absolute; top: 5px; left: 0px; font-size: 30px; font-weight: 400; color: white; font-family: 'times new roman'">
        CRM &nbsp;<span style="font-size: 12px;">&copy;2017&nbsp;动力节点</span></div>
</div>

<div style="position: absolute; top: 120px; right: 100px;width:450px;height:400px;border:1px solid #D5D5D5">
    <div style="position: absolute; top: 0px; right: 60px;">
        <div class="page-header">
            <h1>登录</h1>
        </div>
        <form action="workbench/index.html" class="form-horizontal" role="form">
            <div class="form-group form-group-lg">
                <div style="width: 350px;">
                    <input class="form-control" id="loginAct" type="text" placeholder="用户名">
                </div>
                <div style="width: 350px; position: relative;top: 20px;">
                    <input class="form-control" id="loginPwd" type="password" placeholder="密码">
                </div>
                <div  class="checkbox" style="position: relative;top: 30px; left: 10px;">
                    <label>
                        <input id="rememberMe" type="checkbox"> 十天内免登录
                    </label>
                </div>
                <button type="button" id="btnLogin" class="btn btn-primary btn-lg btn-block"
                        style="width: 350px; position: relative;top: 45px;">登录
                </button>
            </div>
        </form>
    </div>
</div>
</body>
</html>


<script>
    $(function () {
        
        function automaticLogin() {

            $.ajax({
                // 异步请求的地址
                url: "/login/automaticWriting.action",
                // 默认是get请求
                type: "get",
                // 后端返回数据的格式JSON
                dataType: "json",

                // 请求之前做的事情
                beforeSend: function (XMLHttpRequest) {
                    console.log("请求之前做的事情.......");
                },

                // 请求成功做的事情
                success: function (data, textStatus) {
                    console.log("请求成功做的事情........");

                    if (data['result'] == "success"){
                        console.log(data);

                        $("#loginAct").val(data.data.loginAct);
                        $("#loginPwd").val(data.data.loginPwd);
                        $("#rememberMe").prop("checked", true);

                        $.ajax({
                            url: "/login/automaticLogin.action",
                            type: "post",
                            dataType: "json",
                            data: {
                                loginAct:$("#loginAct").val(),
                                loginPwd:$("#loginPwd").val(),
                                rememberMe:$("#rememberMe").prop("checked")
                            },
                            beforeSend: function (XMLHttpRequest) {

                            },
                            error: function (XMLHttpRequest, textStatus, errorThrown) {

                            },
                            success: function (data, textStatus, jqXHR) {

                                if (data['result'] == "success") {
                                    window.location="workbench/index.html";
                                } else {
                                    window.alert(data['mess']);
                                }
                            },
                            complete: function (XMLHttpRequest, textStatus) {
                            }
                        });
                    }

                },

                // 请求失败做的事情
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    console.log("请求失败做的事情.......");
                },

                // 请求完毕做的事情
                complete: function (XMLHttpRequest, textStatus) {
                    console.log("请求完毕做的事情.......");
                }
            });

        }

        automaticLogin();
        

        $("#btnLogin").click(function () {
            $.ajax({
                url: "/login/in.action",
                type: "post",
                dataType: "json",
                data: {
					loginAct:$("#loginAct").val(),
					loginPwd:$("#loginPwd").val(),
                    rememberMe:$("#rememberMe").prop("checked")
				},
                beforeSend: function (XMLHttpRequest) {

                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {

                },
                success: function (data, textStatus, jqXHR) {

                    if (data['result'] == "success") {
                       window.location="workbench/index.html";
                    } else {
                        window.alert(data['mess']);
                    }
                },
                complete: function (XMLHttpRequest, textStatus) {
                }
            });
        });

    });


</script>